package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 章节管理
 */
@RestController
@RequestMapping("admin/voc")
public class VocChapterController {

    @Autowired
    private VocChapterService vocChapterService;

    /**
     * 添加章节
     * @param vocChapterCommand 章节请求体
     * @return
     */
    //@SaAdminCheckPermission("super-admin")
    @PostMapping("chapter")
    public Result addChapter(@RequestBody VocChapterCommand vocChapterCommand){
        vocChapterService.addChapter(vocChapterCommand);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @PutMapping("chapter")
    public Result updateChapter(@RequestBody VocChapterCommand vocChapterCommand){
        vocChapterService.updateChapter(vocChapterCommand);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @GetMapping("chapters/list")
    public Result<PageDTO<VocChapterDTO>> getChapterPage(VocChapterPageRequest pageQuery){
        PageDTO<VocChapterDTO> chapterPage = vocChapterService.getChapterPage(pageQuery);

        return Result.ok(chapterPage);
    }

    //@SaAdminCheckPermission("super-admin")
    @DeleteMapping("chapter/{chapterId}")
    public Result deleteVocBook(@PathVariable("chapterId") Long chapterId){
        vocChapterService.deleteChapter(chapterId);
        return Result.ok();
    }

    //@SaAdminCheckPermission("super-admin")
    @DeleteMapping("chapters")
    public Result deleteBookCategory(@RequestBody BatchDeleteCommand command){
        vocChapterService.deleteChapters(command);
        return Result.ok();
    }
}
